﻿using Common.ServiceDiscovery.Abstractions;
using Common.ServiceDiscovery.Implementation;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace Common.ServiceDiscovery.Extensions
{
    public static class ServiceCollectionExtensions
    {
        ///// <summary>
        ///// 添加服务发现
        ///// </summary>
        ///// <param name="services"></param>
        ///// <param name="action"></param>
        ///// <returns></returns>
        //public static IServiceDiscoveryBuilder AddServiceDiscovery(this IServiceCollection services, Action<IServiceDiscoveryBuilder> action)
        //{
        //    var service = services.First(x => x.ServiceType == typeof(IConfiguration));
        //    var configuration = (IConfiguration)service.ImplementationInstance;
        //    var builder = new ServiceDiscoveryBuilder(services, configuration);
        //    action(builder);
        //    return builder;
        //}
        /// <summary>
        /// 添加服务发现
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configuration"></param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static IServiceDiscoveryBuilder AddServiceDiscovery(this IServiceCollection services, IConfiguration configuration, Action<IServiceDiscoveryBuilder> action)
        {
            var builder = new ServiceDiscoveryBuilder(services, configuration);
            action(builder);
            return builder;
        }
    }
}
